﻿import math

def is_prime(a):
    for i in range(2, int(a / 2) + 1):
        if a % i == 0:
            return False
    return True

def main():
    nums = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    first, second, three = input().split()
    f, s, t = -1, -1, -1
    for i in range(10):
        if first == nums[i]:
            f = i
        if second == nums[i]:
            s = i
        if three == nums[i]:
            t = i
    if f == -1 or s == -1 or t == -1:
        print("Wrong input")
        return
    res_num = f * 100 + s * 10 + t
    number_minus = res_num
    number_plus = res_num
    while True:
        if is_prime(number_plus):
            break
        number_plus += 1
    while True:
        if is_prime(number_minus):
            break
        number_minus -= 1
    print( end="")
    if abs(number_minus - res_num) < abs(number_plus - res_num):
        print(number_minus)
    elif abs(number_minus - res_num) > abs(number_plus - res_num):
        print(number_plus)
    else:
        print(number_plus)

if __name__ == "__main__":
    main()
